package svgundoredo;

/**
 * This class contain all command actions to be store in stack
 */
import java.util.Stack;

public class CommandStack extends AbstractCommand
{
    private Stack<AbstractCommand> undo = new Stack<AbstractCommand>();
    private Stack<AbstractCommand> redo = new Stack<AbstractCommand>();
    @SuppressWarnings("unused")
    private AbstractCommand command;
    
    public CommandStack()
    {
    }
    
    /**
     * This method take the command and add to the stack
     * 
     * @param command
     *            undo redu comnnad such, addElement moving shape etc
     */
    public void addToStack(AbstractCommand command)
    {
        // TODO Auto-generated method stub
        this.command = command;
        undo.push(command);
        redo = null;
        redo = new Stack<AbstractCommand>();
    }
    
    /*
     * This redo command is to reload to the stack
     */
    public void redo()
    {
        if (!redo.isEmpty())
        {
            AbstractCommand tmp = redo.pop();
            undo.push(tmp);
            tmp.execute();
        }
    }
    
    @Override
    public void undo()
    {
        if (!undo.isEmpty())
        {
            AbstractCommand tmp = undo.pop();
            redo.push(tmp);
            tmp.undo();
        }
    }
    
    @Override
    public void execute()
    {
        // TODO Auto-generated method stub
        
    }
    
    public Stack<AbstractCommand> getUndo()
    {
        return undo;
    }
    
    public Stack<AbstractCommand> getRedo()
    {
        return redo;
    }
    
    public boolean checkUndo()
    {
        if (undo.isEmpty())
            return false;
        else
            return true;
    }
    
    public boolean checkRedo()
    {
        if (redo.isEmpty())
            return false;
        else
            return true;
    }
}
